#pragma once
#include "utils.h"
#include "model_process.h"
#include "acl/acl.h"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <cstdint>
#include <opencv2/videoio.hpp>


class OpenPoseProcess : public ModelProcess
{
public:
    OpenPoseProcess();
    OpenPoseProcess(string modelPath);
    Result Init();
    Result InitResource();
    Result InitModel(const string modelPath);
    Result Preprocess(string& imageFile);
    Result Preprocess(cv::Mat image);
    Result Inference(aclmdlDataset*& openposeOutput);
    Result Postprocess(aclmdlDataset*& openposeOutput, float motion_data[1][3][FRAME_LENGTH][18]); // for video
    Result Postprocess(aclmdlDataset*& openposeOutput,string imagePath); // image-only
    Result Postprocess(aclmdlDataset*& openposeOutput,cv::Mat& frame); // for video
    void fileProcess(string filepath,bool if_break,bool write_data);
    void imageProcess(string imagePath);
    void videoProcess(string imagePath);
    void txtProcess(string txtPath);
    void presenterProcess(string imagePath);
    void ProcessMotionData();
    Result DeInit();


private:
    // OpenPose model: (1,3,120,160) -- NCHW
    // (1,160,128,3) -- NHWC
    int32_t deviceId_;
    aclrtContext context_;
    aclrtStream stream_;
    void* poseInputBuf_;
    uint32_t poseInputBufSize_;
    ascend::presenter::Channel* channel_;
    string modelPath_;
    void EncodeImage(vector<uint8_t>& encodeImg, cv::Mat& origImg);
    void SendImage(cv::Mat& image);
    Result OpenPresenterChannel();


};
